create database DIEN_THOAI
go
use DIEN_THOAI
go
----tao bang Dang nhap
create table Dang_Nhap
(
TenDangNhap nvarchar(50) primary key,
MatKhau nvarchar(50),
Email nvarchar(50),
CMND int,
HoVaTen nvarchar(50),
NgaySinh datetime,
DienThoai int,
DiaChi nvarchar(100),
Tinh_TP nvarchar(50),
Quyen int
) 
go
-----tao bang hang san xuat
create  table Hang_SX
(
TenHang nvarchar(50)primary key,
)
go


---tao bang quang cao
create table QUANG_CAO
(
STT int identity(1,1) primary key,
TenCty nvarchar(50),
Hinh_minh_hoa nvarchar(50),
Href nvarchar(50),
Ngay_bat_dau datetime,
Ngay_het_han datetime
)
-----tao bang san pham
create  table SAN_PHAM
(
TenSp nvarchar(50) primary key,
SoLuong int,
KieuDang nvarchar(50),
TenHang nvarchar(50) FOREIGN KEY REFERENCES Hang_SX
ON UPDATE CASCADE
ON DELETE CASCADE,
NamSX datetime,
Gia int,
GiaKM int,
Hinh nvarchar(50),
MP3 bit,
Camera nvarchar(50),
Bluetooth bit,
G3 bit,
Wifi nvarchar(50),
GPRS bit,
XemPhim nvarchar(50),
FMRadio bit,
XemTiVi bit,
Game nvarchar(50),
LoaNgoai bit,
NhacChuong nvarchar(50),
TheNho nvarchar(50),
BoNhoTrong nvarchar(50),
BangTan nvarchar(50),
MangSuDung nvarchar(50),
BaoHanh nvarchar(50),
CacTinh_NK nvarchar(50),
Ngay_cap_nhat datetime,
Hinh2 nvarchar(50)
)
----TAO BANG GOP Y KIEN VE WEBSITE
create table Gop_Y
(
IDGOPY INT IDENTITY(1,1) PRIMARY KEY,
HOVATEN NVARCHAR(50),
EMAIL NVARCHAR(100),
TIEUDE NVARCHAR(250),
NOIDUNG NTEXT,
NGAY_GUI DATETIME
)
go
-------
----------------------------------TAO BANG BANNER
CREATE TABLE BANNER
(
	ID INT IDENTITY(1,1) PRIMARY KEY,
	HINH NVARCHAR(50),
	NGAYCAPNHAT DATETIME
)
--=====================================================================================
create  PROCEDURE themdienthoai
@TenSp nvarchar(50),
@SoLuong int,
@KieuDang nvarchar(50),
@Tenhang nvarchar(50),
@NamSX datetime,
@Gia int,
@GiaKM int,
@Hinh nvarchar(50),
@MP3 bit,
@Camera nvarchar(50),
@Bluetooth bit,
@G3 bit,
@Wifi nvarchar(50),
@GPRS bit,
@XemPhim nvarchar(50),
@FMRadio bit,
@XemTiVi bit,
@Game nvarchar(50),
@LoaNgoai bit,
@NhacChuong nvarchar(50),
@TheNho nvarchar(50),
@BoNhoTrong nvarchar(50),
@BangTan nvarchar(50),
@MangSuDung nvarchar(50),
@BaoHanh nvarchar(50),
@CacTinh_NK nvarchar(50),
@Ngay_cap_nhat datetime,
@hinh2 nvarchar(50)
AS
	insert into SAN_PHAM values(@TenSp ,@SoLuong ,@KieuDang,@Tenhang ,@NamSX ,@Gia ,@GiaKM ,@Hinh ,@MP3 ,@Camera ,@Bluetooth ,@G3 ,@Wifi ,@GPRS ,@XemPhim ,@FMRadio ,@XemTiVi ,@Game ,@LoaNgoai ,@NhacChuong ,@TheNho ,@BoNhoTrong ,@BangTan ,@MangSuDung ,@BaoHanh ,@CacTinh_NK ,@Ngay_cap_nhat,@Hinh2 )
	RETURN
	


-------------------------------------------
create PROCEDURE capnhatinfo
@TenDangNhap nvarchar(50),
@MatKhau nvarchar(50),
@Email nvarchar(50),
@CMND int,
@HoVaTen nvarchar(50),
@NgaySinh datetime,
@DienThoai int,
@DiaChi nvarchar(100),
@Tinh_TP nvarchar(50),
@Quyen int
As
	update Dang_Nhap set MatKhau=@MatKhau,Email=@Email,CMND=@CMND,HoVaTen=@HoVaTen,NgaySinh=@NgaySinh,DienThoai=@DienThoai,DiaChi=@DiaChi,Tinh_TP=@Tinh_TP,Quyen=@Quyen where TenDangNhap=@TenDangNhap
--------------------------------------------
create PROCEDURE SP_InS_GOPY
@HOVATEN nvarchar(50),
@EMAIL nvarchar(100),
@TIEUDE nvarchar(255),
@NOIDUNG ntext,
@NGAY_GUI datetime
AS
	insert into gop_Y values(@HOVATEN,@EMAIL,@TIEUDE,@NOIDUNG,@NGAY_GUI)
	RETURN
